Functions.php
<?php
namespace GitBent\ScrawlExt;
class Functions extends \Tlf\Scrawl\Extension {
protected $regexes = [
'function' => '/\ *function\ *([a-zA-Z\_].+)\(\)/'
];
protected $funcList = [];
public function onSourceFileFound($srcFile){
if ($srcFile->ext!='bash')return;
$content = $srcFile->content();
$didMatch = preg_match_all($this->regexes['function'], $content, $matches, PREG_SET_ORDER);
if (!$didMatch)return;
foreach ($matches as $match){
$funcName = $match[1];
$parts = explode('_', $funcName);
$group = array_shift($parts);
$funcName = implode(' ', $parts);
if (trim($funcName)=='')continue;
$this->funcList[$group][$funcName] = $srcFile->relPath;
}
}
public function onSourceFilesDone(){
$content = "# All bent commands";
foreach ($this->funcList as $group=>$func){
$content .= "\n\n## bent $group [command]";
foreach($func as $funcName=>$relPath){
$content .= "\n- ".$funcName;
}
}
$this->scrawl->addOutput('file', "AllFunctions.md", $content);
}
}